* Who leaves money on the table: Summary stats by quartile of break even rate *
* Adding the column with EL borrowers *
*------------------------------------------------------------------------------*

capture program drop prepare_table_quartiles
program prepare_table_quartiles
	gen CTI = purchaseprice / gross_income		// housing Consumption To Income
	gen ETI = (loan_final + deposit_final) / gross_income		// housing Exposure To Income
	
	collapse bkhp_mortgage ${tabvarlist} CTI ETI, by(bkhp_mortgage_quartile)
	xpose, varname clear
	order _varname
end


* COLUMN 5: Stats for those who took an EL (2013-2015, 2-year fixed) *
*------------------------------------------------------------------------------*
use "${projectdir}\\data\HTB_main", replace
keep if htb_dummy == 1
keep if inrange(date, mdy(4, 2, 2013), mdy(4, 2, 2015)) & dealtype == 2 & LTV>20
keep if ratetype == 1 // Fixed

gen bkhp_mortgage = .
gen bkhp_mortgage_quartile = .
prepare_table_quartiles
rename v1 v5

drop in 1

save "${tabledir}\table_quartiles_c5", replace 


* Quartiles of break-even rates *
*------------------------------------------------------------------------------*
use "${datadir}\HTB_main_cleaned_counterfactual_sub", replace
egen bkhp_mortgage_quartile = xtile(bkhp_mortgage), nq(4)

prepare_table_quartiles

drop in 1	// bkhp_mortgage_quartile = 1, 2, 3, 4
drop v5 	// obs with missing bkhp_mortgage_quartile

merge 1:1  _varname using "${tabledir}\table_quartiles_c5", nogen

drop if regexm(_varname, "equity")		

format v* %6.2f
table_diff_format
latexTable


*--- Output
outsheet using "${tabledir}\table_bkhpsub_0.tex" ///
	if regexm(_varname, "Housing"), replace noquote nonames
	
outsheet using "${tabledir}\table_bkhpsub_1.tex" ///
	if regexm(_varname, "Break-even"), replace noquote nonames
	
outsheet using "${tabledir}\table_bkhpsub_2.tex" ///
	if regexm(_varname, "Age|First time"), replace noquote nonames
	
outsheet using "${tabledir}\table_bkhpsub_3.tex" ///
	if regexm(_varname, "quad Gross income"), replace noquote nonames
	*if regexm(_varname, "quad Gross income|[Ee]mployed"), replace noquote nonames

outsheet using "${tabledir}\table_bkhpsub_4.tex" ///
	if regexm(_varname, "value|Down|Interest|Maturity"), replace noquote nonames
	
outsheet using "${tabledir}\table_bkhpsub_5.tex" ///
	if regexm(_varname, "LTV"), replace noquote nonames

outsheet using "${tabledir}\table_bkhpsub_6.tex" ///
	if regexm(_varname, "LTI"), replace noquote nonames

outsheet using "${tabledir}\table_bkhpsub_7.tex" ///
	if regexm(_varname, "Payment"), replace noquote nonames
